/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.pod.hoteishilton.dao;

import edu.pod.hoteishilton.model.Hotel;
import java.rmi.RemoteException;
import java.util.HashMap;

/**
 *
 * @author thiagotigaz
 */
public class DAOHotel extends DAOFile implements IDAOHotel {

    private static HashMap hoteis;

    public DAOHotel() throws RemoteException {
        if (hoteis == null) {
            if(getManager().getDatabase().containsKey("hotel")){
                hoteis = getManager().getDatabase().get("hotel");
            }else{
                hoteis = new HashMap();
                getManager().getDatabase().put("hotel", hoteis);
                getManager().refresh();
            }
        }
    }
    
    @Override
    public void persist(Hotel hotel) throws RemoteException{
        hoteis.put(hotel.getApelido(), hotel);
        getManager().refresh();
   }
    
    @Override
    public void merge(Hotel hotel) throws RemoteException{
        persist(hotel);
    }
    
    public void remove(Hotel hotel) throws RemoteException{
        hoteis.remove(hotel.getApelido());
        getManager().refresh();
    }

    @Override
    public HashMap getHoteis() throws RemoteException {
        return hoteis;
    }

    @Override
    public Hotel getHotel(String apelido) throws RemoteException {
        if(hoteis.containsKey(apelido)){
            return (Hotel) hoteis.get(apelido);
        }
        return null;
    }

    @Override
    public HashMap getReservas(String apelido) throws RemoteException {
        return ((Hotel) hoteis.get(apelido)).getReservas();
    }

}
